package com.sqx.modules.riderLine.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.modules.riderLine.entity.RiderLine;
import com.sqx.modules.riderLine.dao.RiderLineDao;
import com.sqx.modules.riderLine.service.RiderLineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.sqx.common.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 骑手在线时长 服务实现类
 * @author wuChang
 * @since 2024-05-20
 */
@Service
public class RiderLineServiceImp extends ServiceImpl<RiderLineDao, RiderLine> implements RiderLineService {


    @Override
    public Result saveRiderLine(RiderLine riderLine) {
        if (riderLine.getLineId() != null) {
            return Result.upStatus(baseMapper.updateById(riderLine));
        } else {
            return Result.upStatus(baseMapper.insert(riderLine));
        }
    }

    @Override
    public IPage<RiderLine> getRiderLineList(Integer page, Integer limit, RiderLine riderLine) {
        Page<RiderLine> pages;
        if (page != null && limit != null) {
            pages = new Page<>(page, limit);
        } else {
            pages = new Page<>();
            pages.setSize(-1);
        }
        return baseMapper.selectPage(pages, new QueryWrapper<>(riderLine).orderByAsc("start_time"));
    }

    @Override
    public Integer getNowRiderLine(Long userId) {
        return baseMapper.getNowRiderLine(userId);
    }

    @Override
    public RiderLine getNowOneLine(Long userId) {
        return baseMapper.getNowOneLine(userId);
    }

    @Override
    public BigDecimal getDayLine(Long userId) {

        return baseMapper.getDayLine(userId);

    }
}
